from django.db import models
from rbac.models import UserInfo as RbacUserInfo


class Department(models.Model):
    """
    部门表
    """
    title = models.CharField(verbose_name='班级', max_length=32)

    def __str__(self):
        return self.title


class UserInfo(RbacUserInfo):
    """
    用户表
    """
    phone = models.CharField(verbose_name='联系方式', max_length=32)
    level_choices = (
        (1, '大一'),
        (2, '大二'),
        (3, '大三'),
    )
    level = models.IntegerField(verbose_name='年级', choices=level_choices, null=True, blank=True)

    depart = models.ForeignKey(verbose_name='班级', to='Department',on_delete=models.CASCADE, null=True, blank=True)


class Host(models.Model):
    """
    主机表
    """
    hostname = models.CharField(verbose_name='主机名', max_length=32)
    ip = models.GenericIPAddressField(verbose_name='IP', protocol='both')
    depart = models.ForeignKey(verbose_name='归属部门', to='Department',on_delete=models.CASCADE)

    def __str__(self):
        return self.hostname


class Customer(models.Model):
    """
    客户表
    """
    name = models.CharField(verbose_name='姓名', max_length=32)
    age = models.CharField(verbose_name='年龄', max_length=32)
    email = models.EmailField(verbose_name='邮箱', max_length=32)
    company = models.CharField(verbose_name='公司', max_length=32)

    def __str__(self):
        return self.name


class Notice(models.Model):
    title = models.CharField(max_length=100,verbose_name="标题")
    author = models.ForeignKey(UserInfo, on_delete=models.DO_NOTHING, verbose_name="发表人", null=True)
    created_time = models.DateTimeField(auto_now_add=True, verbose_name="发布时间")
    content = models.TextField(verbose_name="内容")

    class Meta:
        ordering = ['-created_time']

    def __str__(self):
        return self.title